<h2><?= Yii::t('module_file','Upload Form'); ?></h2>

<div class="form">
<?php $form=$this->beginWidget('CActiveForm', array(
	'id'=>'upload-form',
	'enableClientValidation'=>true,
	'clientOptions'=>array(
		'validateOnSubmit'=>true,
	),
	'htmlOptions'=>array(
//		'class' => 'form-horizontal',
		'enctype' => 'multipart/form-data',
	)
)); 

	echo $form->hiddenField($model, 'type', array("id" => "uploadType"));
?>

	<ul id="tabs" class="nav nav-tabs">
		<li class="<? if ($model->type == "file") echo "active"; ?>">
			<a data-toggle="tab" href="file"><?= Yii::t('module_file', 'File'); ?></a>
		</li>
		<li class="<? if ($model->type == "message") echo "active"; ?>">
			<a data-toggle="tab" href="message"><?= Yii::t('module_file', 'Message'); ?></a>
		</li>
	</ul>
	
	<div class="control-group">
		<?= $form->labelEx($model,'userName', array("class"=>"control-label")); ?>
		<div class="controls"><?= $form->textField($model,'userName', array("class"=>"input-xlarge")); ?></div>
		<?= $form->error($model,'userName'); ?>
	</div>

	<div class="control-group tab file <? if ($model->type == "message") echo "hide"; ?>">
		<?= $form->labelEx($model,'filename', array("class"=>"control-label")); ?>
		<div class="controls"><?= $form->fileField($model,'filename', array("class"=>"input-xlarge")); ?></div>
		<?= $form->error($model,'filename'); ?>
	</div>

	<div class="control-group tab message <? if ($model->type == "file") echo "hide"; ?>">
		<?= $form->labelEx($model,'message', array("class"=>"control-label")); ?>
		<div class="controls"><?= $form->textArea($model,'message', array("class"=>"input-xlarge")); ?></div>
		<?= $form->error($model,'message'); ?>
	</div>
	

	<div class="form-actions">
		<?= CHtml::submitButton(Yii::t('module_file', 'Upload'), array("class"=>"btn btn-primary")); ?>
	</div>

<?php $this->endWidget(); ?>
</div><!-- form -->

<script type="text/javascript">
	$(document).ready(function(){
		$("#tabs a").click(function(e){
			e.preventDefault();
			tab = $(this).attr('href');
			
			$("#tabs li").each(function(){
				$(this).removeClass("active");
			});
			$(this).parent().addClass("active");
			
			$("div.tab").each(function(i){
				$(this).addClass("hide");
			});
			$("div.tab."+tab).removeClass("hide");
			
			$("#uploadType").val(tab);
		});
	});
</script>